﻿using BaseUI;
using BLL;
using System;
using System.Data;
using System.Web.UI.WebControls;
using Thksoft.Module.DataDetail;

namespace Thksoft.UserCotrols
{
    public partial class PlanDetailSum_Week : BaseControl
    {
        private QS_PLANWEEKAPPLYBLL applyWeekBll = new QS_PLANWEEKAPPLYBLL();
        public DataTable dt;

        protected void Page_Load(object sender, EventArgs e)
        {
            BindDt();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        public void BindDt()
        {
            var pPage = this.Page as ProjectFundDetail;
            dt = new DataTable();
            if (pPage.dtYear != null && pPage.dtYear.Rows.Count > 0 && Convert.ToDecimal(pPage.busId) > 0)
            {
                FORM_KEY1.Value = pPage.dtYear.Rows[0]["N_YEAR"].ToString();
                FORM_KEY2.Value = pPage.dtYear.Rows[0]["N_MONTH"].ToString();
                FORM_KEY3.Value = pPage.dtYear.Rows[0]["N_WEEK"].ToString();
                lblTime.Text = pPage.valTime;
                lblUser.Text = pPage.valUser;
                lblyear.Text = pPage.myDate;
                lbldw.Text = pPage.cmyName;

                lblBzyj.Text = pPage.dtYear.Rows[0]["C_REAMRK"].ToString();
                this.hidId.Value = pPage.dtYear.Rows[0]["N_MONTHAPP_ID"].ToString() + "@" + pPage.busId;

                dt = new QS_PLANWEEKAPPLYBLL().GetDataByBid(pPage.busId, lognUser.USER_NAME);
                if (dt != null && dt.Rows.Count > 0)
                {
                    HiddenField3.Value = dt.Rows[0]["n_weekapp_id"].ToString();
                }
                ViewState["datatable"] = dt;
                gvMonthFunds.DataSource = dt;
                gvMonthFunds.DataBind();
            }
            else
            {
                MessageBox.Show(Page, "【系统提示】没有查询到相关数据集！");
                lblTime.Text = "";
                lblUser.Text = "";
                lblyear.Text = "";
                lblBzyj.Text = "";
                lbldw.Text = "";
                gvMonthFunds.DataSource = dt;
                gvMonthFunds.DataBind();
                return;
            }
        }

        protected void gvMonthFunds_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string type = ((Label)e.Row.FindControl("lbltype")).Text;
                var ifdetails = ((HiddenField)e.Row.FindControl("HiddenField1")).Value == "1" ? true : false;
                string sss = ((Label)e.Row.FindControl("lblProID")).Text;
                if (type == "0")
                {
                    e.Row.Attributes["style"] = "background-color:#B2D8FF;font-size: 14px";
                }
                else if (type == "1")
                {
                    e.Row.Attributes["style"] = "background-color:#CCCCCC;font-size: 13px;";
                }
                else if (type == "2")
                {
                    /*
                    Control m = new ImageField();
                    m.HeaderImageUrl = "/Images/XiangXi.png";
                    e.Row.Cells[8].Controls.Add(m);*/
                }
            }
        }

        /// <summary>
        /// 重新加载数据(子表信息)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ReLoadClick(object sender, EventArgs e)
        {
            foreach (GridViewRow row in gvMonthFunds.Rows)
            {
                string proId = ((Label)row.FindControl("lblProID")).Text;
                string type = ((Label)row.FindControl("lbltype")).Text;
                var ifdetails = ((HiddenField)row.FindControl("HiddenField1")).Value == "1" ? true : false;
                //if (type == "2" && ifdetails)
                //{
                //    //查询详情表的值
                //    var applyId = Convert.ToInt32(HiddenField3.Value);
                //    row.Cells[4].Text = applyWeekBll.GetMoneyByDetails(applyId, Convert.ToInt32(proId)).ToString();
                //    var code = ((HiddenField)row.FindControl("HiddenField2")).Value;
                //    row.Cells[4].Attributes["onclick"] = "app1.ToDetails(" + HiddenField3.Value + ",3," + proId + ",'" + code + "')";
                //}
            }
        }

        public void BindDaodu()
        {
            //var dt = (DataTable)ViewState["datatable"];
            //dt.Columns["n_proid"].ColumnName = "编号";
            //dt.Columns["C_PRONAME"].ColumnName = "项目名称";
            //dt.Columns["N_MONTHAMOUNT"].ColumnName = "月度资金计划审批金额";
            //dt.Columns["N_SYAMOUNT"].ColumnName = "本月累计已拨付资金";
            //dt.Columns["N_AMOUNT"].ColumnName = "本周资金计划";
            //dt.Columns["n_useamount"].ColumnName = "本周已拨付资金";
            //dt.Columns["amountpercent"].ColumnName = "本周已拨付资金百分比";
            //dt.Columns["N_AMOUNT1"].ColumnName = "本周上报资金计划";
            //dt.Columns["N_AMOUNT2"].ColumnName = "本周资金计划审批金额";
            //dt.Columns["C_REMARK2"].ColumnName = "本周财务资产部审批意见";
            //dt.Columns.Remove("n_weekdetail_id");
            //dt.Columns.Remove("n_weekapp_id");
            //dt.Columns.Remove("N_TYPE");
            //dt.Columns.Remove("IF_DETAILS");
            //dt.Columns.Remove("DETAILS_CODE");
            //dt.Columns.Remove("N_PARENTID");
            //dt.Columns.Remove("N_NUM1");
            //dt.Columns.Remove("N_NUM2");
            //dt.Columns.Remove("c_proweeknum");
            //dt.Columns.Remove("C_REMARK");
            ////dt.Columns.Remove("N_AMOUNT");
            ////dt.Columns.Remove("n_useamount");

            var execll = new BasePage();
            //execll.toExecl1(dt, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "周资金计划申请表");
            execll.toExecl1(Panel1, "周资金计划申请表" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString());
        }

        public void BindPrint()
        {
            var key = Guid.NewGuid().ToString();
            Session[key] = FORM_PRINT_VALUE.Value;
            MessageBox.ResponseScript(Page, "top.MessageBox.Print({Value:\"ID=HTML&VALUE=" + key + "\",Area:[\"800px\",\"500px\"],Scrollbar:true})");
        }
    }
}